home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Source Code / MAP Viewer / Brush.h < prev    next >
C/C++ Source or Header  |  2003-10-09  |  4KB  |  194 lines

  1. /*
  2. Half-Life MAP viewing utility.
  3. Copyright (C) 2003  Ryan Samuel Gregg
  4.  
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18. */
  19.  
  20. #pragma once
  21. #include "stdafx.h"
  22. #include "WorldObject.h"
  23. #include "Face.h"
  24. #include "Frustum.h"
  25. #include "TextureManager.h"
  26.  
  27. __gc class CBrush : public CWorldObject
  28. {
  29. private:
  30.     Color3uc Color;
  31.     bool bCulled;
  32.     BoundingBox Box;
  33.     ArrayList *Faces;
  34.  
  35. public:
  36.     CBrush(CConfig *Config) : CWorldObject(Config)
  37.     {
  38.         bCulled = false;
  39.  
  40.         Faces = new ArrayList();
  41.     }
  42.  
  43.     void SetColor(unsigned char R, unsigned char G, unsigned char B)
  44.     {
  45.         Color.R = R;
  46.         Color.G = G;
  47.         Color.B = B;
  48.     }
  49.  
  50.     void AddFace(CFace *Face)
  51.     {
  52.         Faces->Add(Face);
  53.     }
  54.  
  55.     ArrayList *GetFaces()
  56.     {
  57.         return Faces;
  58.     }
  59.  
  60.     void UpdateBoundingBoxes()
  61.     {
  62.         CFace *Face;
  63.         Vertex3f *Vertices = static_cast<CFace*>(Faces->get_Item(0))->GetVertices();
  64.  
  65.         Box.vNegBound.X = Vertices[0].X;
  66.         Box.vNegBound.Y = Vertices[0].Y;
  67.         Box.vNegBound.Z = Vertices[0].Z;
  68.         Box.vPosBound.X = Vertices[0].X;
  69.         Box.vPosBound.Y = Vertices[0].Y;
  70.         Box.vPosBound.Z = Vertices[0].Z;
  71.  
  72.         for(int i = 0; i < Faces->Count; i++)
  73.         {
  74.             Face = static_cast<CFace*>(Faces->get_Item(i));
  75.  
  76.             Vertices = Face->GetVertices();
  77.  
  78.             for(int j = 0; j < Face->GetVertexCount(); j++)
  79.             {
  80.                 if(Vertices[j].X < Box.vNegBound.X)
  81.                     Box.vNegBound.X = Vertices[j].X;
  82.  
  83.                 if(Vertices[j].Y < Box.vNegBound.Y)
  84.                     Box.vNegBound.Y = Vertices[j].Y;
  85.  
  86.                 if(Vertices[j].Z < Box.vNegBound.Z)
  87.                     Box.vNegBound.Z = Vertices[j].Z;
  88.  
  89.                 if(Vertices[j].X > Box.vPosBound.X)
  90.                     Box.vPosBound.X = Vertices[j].X;
  91.  
  92.                 if(Vertices[j].Y > Box.vPosBound.Y)
  93.                     Box.vPosBound.Y = Vertices[j].Y;
  94.  
  95.                 if(Vertices[j].Z > Box.vPosBound.Z)
  96.                     Box.vPosBound.Z = Vertices[j].Z;
  97.             }
  98.         }
  99.     }
  100.  
  101.     BoundingBox GetBoundingBox()
  102.     {
  103.         return Box;
  104.     }
  105.  
  106.     bool CullBrush(CFrustum *Frustum)
  107.     {
  108.         bCulled = !Frustum->CubeInFrustum(Box);
  109.  
  110.         if(bCulled)
  111.             Frustum->IncCulled();
  112.  
  113.         return bCulled;
  114.     }
  115.  
  116.     void UpdateTedCoords(CTextureManager *TextureManager)
  117.     {
  118.         for(int i = 0; i < Faces->Count; i++)
  119.         {
  120.             static_cast<CFace*>(Faces->get_Item(i))->UpdateTexCoords(TextureManager);
  121.         }
  122.     }
  123.  
  124.     void DrawBrushTextured()
  125.     {
  126.         if(bCulled)
  127.             return;
  128.  
  129.         for(int i = 0; i < Faces->Count; i++)
  130.         {
  131.             static_cast<CFace*>(Faces->get_Item(i))->DrawFaceTextured();
  132.         }
  133.     }
  134.  
  135.     void DrawBrushSolid()
  136.     {
  137.         if(bCulled)
  138.             return;
  139.  
  140.         glColor3ub(Color.R, Color.G, Color.B);
  141.  
  142.         for(int i = 0; i < Faces->Count; i++)
  143.         {
  144.             static_cast<CFace*>(Faces->get_Item(i))->DrawFaceSolid();
  145.         }
  146.     }
  147.  
  148.     void DrawBrushWireFrame()
  149.     {
  150.         if(bCulled)
  151.             return;
  152.  
  153.         glColor3ub(Color.R, Color.G, Color.B);
  154.  
  155.         for(int i = 0; i < Faces->Count; i++)
  156.         {
  157.             static_cast<CFace*>(Faces->get_Item(i))->DrawFaceWireFrame();
  158.         }
  159.     }
  160.  
  161.     void DrawBrushPoints()
  162.     {
  163.         if(bCulled)
  164.             return;
  165.  
  166.         glColor3ub(Color.R, Color.G, Color.B);
  167.  
  168.         for(int i = 0; i < Faces->Count; i++)
  169.         {
  170.             static_cast<CFace*>(Faces->get_Item(i))->DrawFacePoints();
  171.         }
  172.     }
  173.  
  174.     void Highlight(bool bPrepared)
  175.     {
  176.         if(!bPrepared)
  177.         {
  178.             PrepareHighlight();
  179.         }
  180.  
  181.         for(int i = 0; i < Faces->Count; i++)
  182.         {
  183.             static_cast<CFace*>(Faces->get_Item(i))->Highlight(true);
  184.         }
  185.     }
  186.  
  187.     void Outline()
  188.     {
  189.         for(int i = 0; i < Faces->Count; i++)
  190.         {
  191.             static_cast<CFace*>(Faces->get_Item(i))->Outline();
  192.         }
  193.     }
  194. };